    .orig   x3000
		LEA R0, FIRST   ;R0<-ADDRESS OF FIRST
		LDW R4, R0, #0  ;R4<- X4000
		LDB R1, R4, #0  ;R1<-BYTE
		ADD R6, R4, #0  ;R6<-R4
		
		LDB R2, R4, #4  ;R2<- THE MASK
		LEA R0, B_1		;R0<-ADDRESS OF B_1
		LDB R3, R0, #0  ;R3<-X03
		AND R3, R3, R2  ;R3<-MASK[1:0]

		ADD R5, R3, #0
		BRZ ZERO
		ADD R5, R3, #-1
		BRZ ONE
		ADD R5, R3, #-2
		BRZ TWO
		ADD R5, R3, #-3
		BRZ THREE

ZERO	STB R1, R6, #5
		BR LAST0
ONE		STB R1, R6, #6
		BR LAST0
TWO		STB R1, R6, #7
		BR LAST0	   
THREE	STB R1, R6, #8
	
LAST0	ADD R4, R4, #1	
		LDB R1, R4, #0
		LEA R0, B_2
		LDB R3, R0, #0
		AND R3, R3, R2   ;MASK[3:2]
		RSHFL R3, R3, #2
		
		ADD R5, R3, #0
		BRZ ZERO1
		ADD R5, R3, #-1
		BRZ ONE1
		ADD R5, R3, #-2  
		BRZ TWO1      	
		ADD R5, R3, #-3
		BRZ THREE1
ZERO1	STB R1, R6, #5
	    BR LAST1
ONE1	STB R1, R6, #6
	    BR LAST1
TWO1	STB R1, R6, #7
		BR LAST1 
THREE1  STB R1, R6, #8

LAST1   ADD R4, R4, #1
        LDB R1, R4, #0
		LEA R0, B_3
		LDB R3, R0, #0
		AND R3, R3, R2     ;MASK[5:4]
		RSHFL R3, R3, #4
	
		ADD R5, R3, #0
		BRZ ZERO2
		ADD R5, R3, #-1
		BRZ ONE2
		ADD R5, R3, #-2  
		BRZ TWO2      	
		ADD R5, R3, #-3
		BRZ THREE2
ZERO2	STB R1, R6, #5
	    BR LAST2
ONE2	STB R1, R6, #6
	    BR LAST2
TWO2	STB R1, R6, #7
		BR LAST2 
THREE2  STB R1, R6, #8

LAST2   ADD R4, R4, #1
		LDB R1, R4, #0
		LEA R0, B_4
		LDB R3, R0, #0
		AND R3, R3, R2
		RSHFL R3, R3, #6    ;MASK [7:6]
		
		ADD R5, R3, #0
		BRZ ZERO3
		ADD R5, R3, #-1
		BRZ ONE3
		ADD R5, R3, #-2  
		BRZ TWO3      	
		ADD R5, R3, #-3
		BRZ THREE3
ZERO3	STB R1, R6, #5
	    BR LAST3
ONE3	STB R1, R6, #6
	    BR LAST3
TWO3	STB R1, R6, #7
		BR LAST3 
THREE3  STB R1, R6, #8	
LAST3	NOP 
		
FIRST    .FILL X4000
B_1	 	 .FILL X03
B_2	 	 .FILL X0C
B_3 	 .FILL X30
B_4 	 .FILL XC0
.END

